<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>

<xsl:template match="/">
<menu>
<xsl:for-each select="/site/dir">
<xsl:call-template name="module"/>
</xsl:for-each>
</menu>
</xsl:template>

<xsl:template name="dir">
<xsl:for-each select="dir">
<dir name="{@name}">
<xsl:call-template name="module"/>
</dir>
</xsl:for-each>
</xsl:template>

<xsl:template name="module">
<xsl:for-each select="module">
<xsl:if test="(@enabled='true' or @enabled='1') and (not (@hidden='true' or @hidden='1'))">
<entry>
<xsl:choose>
	<xsl:when test="(menuentry/@link='0') or (menuentry/@link='false')">
		<xsl:apply-templates select="menuentry"/>
	</xsl:when>
<xsl:otherwise>
	<a href="{@name}/"><xsl:apply-templates select="menuentry"/></a>
</xsl:otherwise>
</xsl:choose>
</entry>
</xsl:if>
</xsl:for-each>
<xsl:call-template name="dir"/>
</xsl:template>

<xsl:template match="menuentry">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match='@*|*'>
	<xsl:copy>
		<xsl:apply-templates select="@*|node()|text()"/>
	</xsl:copy>
</xsl:template>

</xsl:stylesheet>